<script type=text/javascript src="/public/js/jquery.js"></script>
<script type=text/javascript src="/public/js/duxui.js"></script>
<script type=text/javascript src="/public/js/dialog/jquery.artDialog.js?skin=default"></script>
<script type=text/javascript src="/public/js/dialog/plugins/iframeTools.js"></script>
<script language="javascript">
//弹出窗口
function urldialog(config,url){
	if(!config.title){
		var config = {
			title:config,
			url:url
		};
	}
	if(!config.width){
		config.width=640;
	}
	art.dialog.open(
		config.url,
		{
			title:config.title,
			width:config.width,
			height:config.height
		}
	);
}
</script>
<div class="dux-tools">
  <div class="bread-head">广告管理 <span class="small">管理网站经常变换的图片</span> </div>
  <br>
  <div class="tools-function clearfix">
    <div class="float-left"> <a class="button button-small bg-main icon-list" href="__URL__"> 广告列表</a> </div>
    <div class="button-group float-right"> <a class="button button-small bg-dot icon-plus dropdown-toggle"> 添加 <span class="downward"></span></a>
      <ul class="drop-menu pull-right">
        <li><a href="__URL__/add">添加广告</a></li>
      </ul>
    </div>
  </div>
</div>
<div class="admin-main">
<form method="post" class="form-x dux-form form-auto" id="form" action="__URL__/{$action}_save/time-<?php echo time(); ?>-ajax-true">
  <div class="panel dux-box  active">
    <div class="panel-head"> <strong>{$action_name}广告</strong> </div>
    <div class="panel-body">
      <div class="form-group">
        <div class="label">
          <label>广告名称</label>
        </div>
        <div class="field">
          <input type="text" class="input" id="name" name="name" size="60" value="<?php echo $info['name'] ?>">
          <div class="input-note">广告名称</div>
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label>广告宽度</label>
        </div>
        <div class="field">
          <input type="text" class="input" id="adsw" name="adsw" size="60" value="<?php echo $info['adsw'] ?>">
          <div class="input-note">广告宽度</div>
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label>广告高度</label>
        </div>
        <div class="field">
          <input type="text" class="input" id="adsh" name="adsh" size="60" datatype="n" value="<?php echo $info['adsh'] ?>">
          <div class="input-note">广告高度</div>
        </div>
      </div>
        <div class="form-group">
          <div class="label">
            <label>状态</label>
          </div>
          <div class="field">
            <div class="button-group button-group-small radio">
              <label class="button <?php if($info['isshow']==1||!isset($info['isshow']))echo ' active'; ?>">
                <input name="isshow" value="1" <?php if($info['isshow']==1||!isset($info['isshow']))echo ' checked="checked"'; ?> type="radio">
                <span class="icon icon-check"></span> 显示</label>
              <label class="button <?php if($info['isshow']==0&&isset($info['isshow']))echo ' active'; ?>">
                <input name="isshow" value="0"<?php if($info['isshow']==0&&isset($info['isshow']))echo ' checked="checked"'; ?> type="radio">
                <span class="icon icon-times"></span> 隐藏</label>
            </div>
            <div class="input-note">广告显示或隐藏</div>
          </div>
        </div>
      <div class="form-group">
        <div class="label">
          <label>广告类型</label>
        </div>
        <div class="field">
          <select name="type" id="type" class="input" onchange="typeinfo();">
            <option value="1"<?php if($info['type']==1)echo ' selected="selected"'; ?>>单张图片</option>
            <option value="6"<?php if($info['type']==6)echo ' selected="selected"'; ?>>多图轮播</option>
            <option value="3"<?php if($info['type']==3)echo ' selected="selected"'; ?>>文字</option>
          </select><span id="btn_add" style="display: <?php if($info['type']==6){echo 'block';}else{echo 'none';} ?>;">
          <button id="add_items" type="button" class="button" onclick="additem();"><b class=" icon-plus"></b> 添加</button>
          </span>
          <div class="input-note">广告类型</div>
        </div>
      </div>
      <div class="form-group" id="body" <?php if($info['type']!=3)echo 'style="display:none"'; ?>>
        <div class="label">
          <label>自定义代码</label>
        </div>
        <div class="field">
          <?php echo module('editor')->get_editor('content'); ?>
        <textarea name="content" style="width:100%; height:350px;" id="content">{$page_info.content html}</textarea>
        <input type="button" onclick="javascript:get_remote_image()" style="margin-top:10px;" class="button_small" value="远程图片本地化" />
        <?php echo module('editor')->get_editor_upload('editor_upload','editor_content') ?>
        <input type="button" id="editor_upload" class="button_small" style="margin-top:10px;" value="上传图片和文件到编辑器" />
        <!--hook-->
        <?php module('common')->plus_hook('content','tools',$info);  ?>
      	<!--hook end-->
          
        </div>
      </div>

      <div class="form-group" id="ad_content" <?php if($info['type']==3)echo 'style="display:none"'; ?>>
        <div class="label">
          <label>图片</label>
        </div>
        <div class="field">
            <table class="default" style="">
          <tbody id="table_img">
              <?php if($info['adfile']!=''){
                  $photo_i=1;
                  foreach(explode('|-|',$info['adfile']) as $v){
                      $s=explode('|,|',$v);
              ?>
                    <tr>
                      <td style="width:80px;">图片地址：</td>
                      <td style="width:150px;">
                      <?php echo module('editor')->get_image_upload('image'.$photo_i,'adfile'.$photo_i,false) ?>
                          <input name="photofile[]" type="text" id="adfile<?php echo $photo_i;?>" value="<?php echo $s[0]; ?>" class="input"></td>
                          <td style="width:80px;"> 
                 <input type="button" id="image<?php echo $photo_i;?>" class="button button-small" value="选择图片" />
</td>
                      <td style="width:80px;">连接地址：</td>
                      <td style="width:150px;"><input name="photourl[]" type="text" value="<?php echo $s[2];?>" class="input" /></td>
                      <td style="width:60px;">名称：</td>
                      <td style="width:130px;"><input name="phototxt[]" type="text" value="<?php echo $s[1];?>" class="input"></td>
                      <td style="width:60px;">排序：</td>
                      <td style="width:90px;"><input name="photonum[]" type="text" style="width:30px;" value="<?php echo $photo_i;?>" class="input"></td>
                      <td style="width:20px;"><a href="javascript:void(0);" rel="<?php echo $s[0]; ?>" class="class_pic"><img align="AbsMiddle" src="/public/images/ico/pic.png" width="14" height="14" alt=""></a></td>
                      <td style="width:40px;"><a class="button bg-red button-small icon-trash-o" href="javascript:;" onclick="item_del(this)" title="删除"></a></td>
                    </tr>
              <?php        
                      $photo_i++;
                  }
                }else{ ?>

            <tr>
              <td style="width:80px;">图片地址：</td>
              <td style="width:150px;">
              	  <?php echo module('editor')->get_image_upload('image1','adfile1',false,'') ?>
                  <input name="photofile[]" type="text" id="adfile1" value="" class="input">
               </td> <td style="width:80px;"> 
                 <input type="button" id="image1" class="button button-small" value="选择图片" />
</td>
              <td style="width:80px;">连接地址：</td>
              <td style="width:150px;"><input name="photourl[]" type="text" value="" class="input" /></td>
              <td style="width:60px;">名称：</td>
              <td style="width:130px;"><input name="phototxt[]" type="text" value="" class="input"></td>
              <td style="width:60px;">排序：</td>
              <td style="width:90px;"><input name="photonum[]" type="text" style="width:30px;" value="" class="input"></td>
              <td style="width:20px;"></td>
              <td style="width:40px;"><a class="button bg-red button-small icon-trash-o" href="javascript:;" onclick="item_del(this)" title="删除"></a></td>
            </tr>
            <?php } ?>
          </tbody>
        </table>
          <div class="input-note">多图或者单张图</div>
        </div>
      </div>

    </div>
    <div class="panel-foot">
      <div class="form-button">
        <div id="tips"></div>
        <?php if(model('user_group')->model_power('ads','add')||model('user_group')->model_power('ads','edit')){ ?>
        <input name="id" type="hidden" value="{$info.id}" />
        <input name="file_id" id="file_id" type="hidden" value="{$file_id}" />
        <button class="button bg-main" type="submit">保存</button>
        <button class="button bg" type="reset">重置</button>
        <?php } ?>
      </div>
    </div>
  </div>
</form>
<script>
$(".class_pic").powerFloat({
    targetMode: "ajax"
});
savelistform({addurl:"__URL__/add",listurl:"__URL__"});
function typeinfo(){
	if($("#type").val()==5){
		$("#body").show();
		$("#gourl").hide();
	}else if($("#type").val()==3){
		$("#body").show();
		$("#gourl").hide();
		$("#ad_content").hide();
	}else{
		$("#body").hide();
		$("#gourl").show();
	}
	if($("#type").val()==6){
		$("#btn_add").show();
	}else{
		$("#btn_add").hide();
	}
}

function additem(){
	var thistmpid = $("#ad_content tr:last input:first").attr("id");
	var thisidnum = thistmpid.replace('adfile','');
	var thisid = parseInt(thisidnum)+1;
	$("#table_img").append('<tr><td style="width:80px;">图片地址：</td><td style="width:150px;"><dd><input name="photofile[]" type="text" id="adfile'+thisid+'" value="" class="input"></td><td style="width:80px;"><input type="button" onclick="img_upload_by_item(\'adfile'+thisid+'\')" class="button button-small" value="选择图片" /></td><td style="width:80px;">连接地址：</td><td style="width:150px;"><input name="photourl[]" type="text" value="" class="input" /></td><td style="width:60px;">名称：</td><td style="width:130px;"><input name="phototxt[]" type="text" value="" class="input"></td><td style="width:60px;">排序：</td><td style="width:90px;"><input name="photonum[]" type="text" style="width:30px;" value="" class="input"></td><td style="width:20px;"></td><td style="width:40px;"><a class="button bg-red button-small icon-trash-o" href="javascript:;" onclick="item_del(this)" title="删除"></a></td></tr>');
//	alert($("tr").length);
//	var current_tr = $(".info table tr:eq(0)");
//	var dom = current_tr.clone(true);
//	$("input",dom).val('');
//	dom.insertAfter(current_tr);
}
 //删除table的一行
function item_del(id){
  if($("tr",$(id).parent().parent().parent()).length>=2) $(id).parent().parent().remove();
  else {
    alert('至少要对应一组信息！');
  }
}
function img_upload_by_item(a)
{
urldialog({
	  title:'图片上传',
	  url:'__APP__/editor/image_upload?id='+a+'&editor=',
	  width:620,
	  height:240
  });
}
</script> 
</div>
